<?php



/**

 * DOCman Ultimate Download Module 1.5

 * @version $Id: mod_docman_ult.php 1.0 2009-09-03 Ahmad Alfy

 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL

 * @link http://www.joomlatools.org/ Official website

 * @link http://www.alfystudio.com/ Module website

 **/



defined('_JEXEC') or die('Restricted access');



//DOCman core interaction API



include_once( $mosConfig_absolute_path."/administrator/components/com_docman/docman.class.php");



global $_DOCMAN, $_DMUSER;

if(!is_object($_DOCMAN)) {

    $_DOCMAN = new dmMainFrame();

    $_DMUSER = $_DOCMAN->getUser();

}



$_DOCMAN->setType(_DM_TYPE_MODULE);

$_DOCMAN->loadLanguage('modules');



require_once($_DOCMAN->getPath('classes', 'utils'));

require_once($_DOCMAN->getPath('classes', 'file'));

require_once($_DOCMAN->getPath('classes', 'model'));



// Getting Parameters



$limits  		= $params->get( 'limits', 3 );

$link			= $params->get( 'link', 'details' );

$sortby			= $params->get( 'sortby', 'date' );

$order			= $params->get( 'order', 'desc' );

$show_icon 		= $params->get( 'show_icon', 1 );

$show_hits 		= $params->get( 'show_hits', 1 );

$show_category 	= $params->get( 'show_category', 1 );

$category_id 	= $params->get( 'category_id', 0 );

$moduleclass_sfx = $params->get( 'moduleclass_sfx' );



$menuid = $_DOCMAN->getMenuId();

$html = '<div class="mod_docman_ult">';

$rows = DOCMAN_Docs::getDocsByUserAccess($category_id , $sortby, $order, $limits);



if (count($rows)) {

	$html .= '<ul class="mod_docman_ult_latest">';

	

	foreach ($rows as $row){

		$doc = new DOCMAN_Document($row->id);

        $catid = $doc->getData('catid');

		$hits = $doc->getData('dmcounter');

        $id = $doc->getData('id');

		

		if ( $link == "details" ) {

			$url = sefRelToAbs( "index.php?option=com_docman&task=doc_details&Itemid=$menuid&gid=$id");

			}else if ( $link == "download" ) {

				$url = sefRelToAbs( "index.php?option=com_docman&task=doc_download&gid=$id&Itemid=$menuid" );

			}else if ( $link == "category" ) {

				$url = sefRelToAbs( "index.php?option=com_docman&task=cat_view&gid=$catid&Itemid=$menuid" );

			}

		

	   	$html .= '<li><a href="'.JRoute::_($url).'">';

        if ($show_icon) $html .= '<img border="0" src="'.$doc->getPath('icon', 1, '16x16').'" alt="icon" /> ';

       	$html .= $doc->getData('dmname');

        if ($show_category) $html .= '<br />('.$row->cat_title.')';

        $html .= '</a>';

        if ($show_hits) $html .= '<span class="dm_hits"> ('.$row->dmcounter.')</span>';

		$html .= '</li>';

    }

    $html .='</ul>';

}else{

	$html .= "<br />"._DML_MOD_NODOCUMENTS;

}

$html .= '</div>';

echo $html;

?>